import Vue from 'vue'
import Vuex from 'vuex'

import {userinfo} from '@/api'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token:'',
    user:{
      username:'',
      ava:''
    }
  },
  getters:{
    vip: state => {
      if(state.user.username === '15934827717'){
        return '张大侠';
      }else{
        return '一介武夫';
      }
    }
  },
  mutations: {
    setToken(state, token){
      state.token = token;
    },
    setUser(state, user){
      state.user = user;
    }
  },
  actions: {
    getUserInfo(context){
      console.log('获取用户信息');
      // Vue.axios.get('http://47.75.46.246:9999/userinfo',{
      //   headers:{
      //     Authorization:'bearer ' + context.state.token
      //   }
      // })
      userinfo()
      .then((res) => {
        console.log(res)
        context.commit('setUser', res.data)
      })
    }
  },
  modules: {
  }
})
